$(function () {
	//点击返回按钮返回上一页
	$(".goBack").bind("click",function(){
//		window.history.back();location.reload();	//强行刷新
//		window.history.go(-1);  //返回上一页
		window.location.href = document.referrer;	//返回上一页并刷新
	});
	//点击全部订单跳转到全部订单界面
	$(".order_ul .all").bind("click",function () {
		window.location.href = "allOrder.html"
	});
	//点击待发货跳转到待发货界面
	$(".order_ul .wait_deliver").bind("click",function () {
		window.location.href = "waitDeliverOrder.html"
	});
	//点击待收货跳转到待收货界面
	$(".order_ul .wait_receipt").bind("click",function () {
		window.location.href = "waitReceiptOrder.html"
	});
	//点击退换货跳转到退换货界面
	$(".order_ul .wait_return").bind("click",function () {
		window.location.href = "tuihuanhuoOrder.html"
	});

	// 获取零元购商城和集分商城的订单总页数
    var zeroPage = 0; // 零元购商城的订单总页数
    var jfscPage = 0; // 集分商城的订单总页数
    var flag1 = true;
    var flag2 = true;
	var zeroCode = 1;
	var JfscCode = 1;
    function getZeroPage(a) {
        return zeroPage = a;
    }
    function getJFSCPage(b) {
        return jfscPage = b;
    }
    function compare(a,b){
        return a >= b ? a : b;
    }
    function Flag1(a){
        return flag1 = a;
    }
    function Flag2(a){
        return flag2 = a;
    }
	function getZeroCode(a){
		return zeroCode = a;
	}
	function getJfscCode(b){
		return JfscCode = b;
	}
	// 加载零元购商城和集分商城的订单
    dropload();
    function dropload() {
        var page = 0; //页码数
        // dropload函数接口设置
        $('.goodOrder').dropload({
            scrollArea: window,
            // 上拉加载更多
            domDown: {
                domClass: 'dropload-down',
                // 滑动到底部显示内容
                domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
                // 内容加载过程中显示内容
                domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
                // 没有更多内容显示提示
                domNoData: '<div class="dropload-noData">我也是有深度的...</div>'
            },
            // 上拉加载更多 回调函数
            loadDownFn: function(me) {
                page++; // 每次请求，页码加1
                if(flag1){
                    var load1 = $.ajax({
                        type: 'post',
                        url: 'http://a.91jfk.com/Product/Order/zero_index?p=' + page,
                        data:{
                            state:'1'
                        },
                        dataType: 'json',
                        success: function(res) {
                            console.log(res);
                            getZeroCode(res.code);
                            getZeroPage(res.totalpage);
                            // data = JSON.parse(res);
                            if (res.nowpage < res.totalpage) {
                                Flag1(true);
                                if (res.code == '1') {
                                    var data = res.msg;
                                    if (data.length > 0) {
                                        for (var i = 0; i < data.length; i++) {
											if(data[i].order_state == '待付款'){
                                                zerowaitPay(data[i].orderid,data[i].order_state,data[i].product,res.nowpage,data[i].product.length,data[i].total);
                                            } 
                                            $('img.lazy'+res.nowpage).lazyload({
                                                placeholder:"/Public/Product/img/loading2.gif",
                                                effect: "fadeIn",
                                                container: $(".allOrderList")
                                            });
                                        }
                                        if(data.length < 3){
                                            // 显示无数据
                                            me.noData();
                                            // 重置
                                            setTimeout(function() {
                                                me.resetload();
                                            }, 1500);
                                        }
                                    }
                                    setTimeout(function() {
                                        // 重置
                                        me.resetload();
                                    }, 1500);
                                    cancelORpay();      //取消订单和付款
                                } else {
                                    // 重置
                                    setTimeout(function() {
                                        me.resetload();
                                    }, 1500);
                                }
                            }else{
                                load1.abort();
                                Flag1(false);
                                if (res.code == '1') {
                                    var data = res.msg;
                                    for (var i = 0; i < data.length; i++) {
                                        if(data[i].order_state == '待付款'){
                                            zerowaitPay(data[i].orderid,data[i].order_state,data[i].product,res.nowpage,data[i].product.length,data[i].total);
                                        }
                                        $('img.lazy'+res.nowpage).lazyload({
                                            placeholder:"/Public/Product/img/loading2.gif",
                                            effect: "fadeIn",
                                            container: $(".allOrderList")
                                        });
                                    }
                                    if(data.length < 3){
                                        // 显示无数据
                                        me.noData();
                                        // 重置
                                        setTimeout(function() {
                                            me.resetload();
                                        }, 1500);
                                    }
                                    cancelORpay();      //取消订单和付款
                                } else {
                                    me.lock();
                                    me.noData();
                                    // 重置
                                    setTimeout(function() {
                                        me.resetload();
                                    }, 1500);
                                }
                            }
                            // 重置
                            setTimeout(function() {
                                me.resetload();
                            }, 1500);
                        },
                        // 加载出错
                        error: function(err) {
                            console.log('Ajax error!');
                            // 即使加载出错，也得重置
                            setTimeout(function() {
                                me.resetload();
                            }, 1500);
                        }
                    });
                }else{
                    var max = compare(zeroPage,jfscPage);
                    if (page > max) {
                        // 再往下已经没有数据，锁定
                        // 显示无数据
                        me.noData();
                        me.lock();
                        // 重置
                        setTimeout(function() {
                            me.resetload();
                        }, 1500);
                    } else {
                        me.unlock();
                    }
                }
                if(flag2){
                    var load2 = $.ajax({
                        type: 'post',
						url: 'http://a.91jfk.com/Product/Ordershop/AllOrderData?p=' + page,
						data:{
							state:1
						},
                        dataType: 'json',
                        success: function(res) {
                            console.log(res);
                            // data = JSON.parse(res);
                            getJfscCode(res.code);
                            getJFSCPage(res.total);
                            if (res.nowpage < res.total) {
                                Flag2(true);
                                if (res.code == '1') {
                                    var data = res.message;
                                    if (data.length > 0) {
                                        for (var i = 0; i < data.length; i++) {
                                            if(data[i].order_state == '待付款'){
                                                waitPay(data[i].order_pay_price,data[i].order_pay_integral, data[i].orderid,data[i].order_state,data[i].detail,res.nowpage,data[i].count,data[i].order_pay_price,data[i].order_pay_integral);
                                            }
                                            $('img.lazy'+res.nowpage).lazyload({
                                                placeholder:"/Public/Product/img/loading2.gif",
                                                effect: "fadeIn",
                                                container: $(".allOrderList")
                                            });
                                        }
                                        if(data.length < 3){
                                            // 显示无数据
                                            me.noData();
                                            // 重置
                                            setTimeout(function() {
                                                me.resetload();
                                            }, 1500);
                                        }
                                    }
                                    setTimeout(function() {
                                        // 重置
                                        me.resetload();
                                    }, 1500);
                                    cancelORpay();      //取消订单和付款
                                } else {
                                    // 重置
                                    setTimeout(function() {
                                        me.resetload();
                                    }, 1500);
                                }
                            }else{
                                load2.abort();
                                Flag2(false);
                                if (res.code == '1') {
                                    var data = res.message;
                                    for (var i = 0; i < data.length; i++) {
                                        if(data[i].order_state == '待付款'){
                                            waitPay(data[i].order_pay_price,data[i].order_pay_integral, data[i].orderid, data[i].order_state, data[i].detail,res.nowpage, data[i].count, data[i].order_pay_price, data[i].order_pay_integral);
                                        }
                                        $('img.lazy'+res.nowpage).lazyload({
                                            placeholder:"/Public/Product/img/loading2.gif",
                                            effect: "fadeIn",
                                            container: $(".allOrderList")
                                        });
                                    }
                                    if(data.length < 3){
                                        // 显示无数据
                                        me.noData();
                                        // 重置
                                        setTimeout(function() {
                                            me.resetload();
                                        }, 1500);
                                    }
                                    cancelORpay();      //取消订单和付款
                                } else {
                                    me.lock();
                                    me.noData();
                                    // 重置
                                    setTimeout(function() {
                                        me.resetload();
                                    }, 1500);
                                }
                            }
                            setTimeout(function() {
                                me.resetload();
                            }, 1500);
                        },
                        // 加载出错
                        error: function(err) {
                            console.log('Ajax error!');
                            console.log(err);
                            // 即使加载出错，也得重置
                            setTimeout(function() {
                                me.resetload();
                            }, 1500);
                        }
                    });
                }else{
                    var max = compare(zeroPage,jfscPage);
                    if (page > max) {
                        // 再往下已经没有数据  锁定
                        // 显示无数据
                        me.noData();
                        me.lock();
                        // 重置
                        setTimeout(function() {
                            me.resetload();
                        }, 1500);
                    } else {
                        me.unlock();
                    }
                }
            }
        });
    }
	
    setTimeout(function(){
        if (zeroCode == 0 && JfscCode == 0) {
            $('.no_order').show();
            $('.no_order .img2').bind('click',function(){
                window.location.href = 'http://a.91jfk.com/Product/Pointshop/point_shop_index.html'
            });
            setTimeout(function(){
                $('div.dropload-noData').fadeOut(1000);
            },200);
        } else{
            $('.kong').hide();
        }
    },1500);
	
	/*参数
	 * orderNum		订单编号
	 * state		订单状态
	 * src			商品图片地址
	 * title		商品名称
	 * price		商品单价
	 * states		商品交易状态
	 * count		单件商品的数量
	 * num			单笔订单里的商品总数
	 * total		单笔订单的总价
	*/
	 //待付款订单
	 //待付款订单
	 function zerowaitPay(orderNum, state, arr, j, num, total) {
        var List = $('.allOrderList');
        var listBox = $('<div class="orderList_box"></div>');
        var list_top = $('<div class="orderList_num"><span>订单编号：</span><span class="orderNum">' + orderNum + '</span><span class="TrsnState">' + state + '</span></div>');
        listBox.append(list_top);
        for (var i = 0; i < arr.length; i++) {
            var list_con = $('<div class="orderList_con"><div class="orderList_con_lt"><div class="lt_imgBox"><img class="IMG lazy'+ j +'" src="/Public/Product/img/loading2.gif" data-original="' + arr[i].thumbnail + '" alt="" /></div></div><div class="orderList_con_rt"><p class="p_top"><span class="goodTitle">' + arr[i].title + '</span><span class="red price">&yen;' + arr[i].price + '</span></p><p class="p_bot"><span class="red count">x' + arr[i].num + '</span></p></div></div>');
            listBox.append(list_con);
        }
        var list_bot = $('<div class="orderList_bot"><p class="num-money">共<span class="good_piece pur">' + num + '</span>件商品，合计：&yen;<span class="allPrice pur">' + total + '元</span>(含运费&yen;3.0)</p><button class="payment fr">付款</button><button class="cancelOrder fr">取消订单</button></div>');
        listBox.append(list_bot);
        List.append(listBox);
    }
	
	//待付款订单     amount1现金总价格    amount2集分总价格
    function waitPay(amount1, amount2, orderNum, state, arr, j, num, total1, total2) {    //total1现金总价格,total2集分总价格
        var List = $('.allOrderList');
        var listBox = $('<div class="orderList_box"></div>');
        if (amount1 != '0.00' && amount2 == '0') {     // 纯现金  value=3
            var list_top = $('<div class="orderList_num"><input type="hidden" value="3" /><span>订单编号：</span><span class="orderNum">' + orderNum + '</span><span class="TrsnState">' + state + '</span></div>');
            listBox.append(list_top);
        } else if (amount1 == '0.00' && amount2 != '0'){   // 纯集分  value=1
            var list_top = $('<div class="orderList_num"><input type="hidden" value="1" /><span>订单编号：</span><span class="orderNum">' + orderNum + '</span><span class="TrsnState">' + state + '</span></div>');
            listBox.append(list_top);
        } else if (amount1 != '0.00' && amount2 != '0'){   // 现金加集分  value=2
            var list_top = $('<div class="orderList_num"><input type="hidden" value="2" /><span>订单编号：</span><span class="orderNum">' + orderNum + '</span><span class="TrsnState">' + state + '</span></div>');
            listBox.append(list_top);
        }
        for (var i = 0; i < arr.length; i++) {  //point_price集分价格 cash_price现金价格
            if (arr[i].cash_price == '0.00' && arr[i].point_price != '0') {   //纯集分商品
                var list_con = $('<div class="orderList_con"><div class="orderList_con_lt"><div class="lt_imgBox"><img class="IMG lazy'+ j +'" src="/Public/Product/img/loading2.gif" data-original="' + arr[i].show_pic + '" alt="" /></div></div><div class="orderList_con_rt"><p class="p_top"><span class="goodTitle">' + arr[i].pname + '</span><span class="red price">&yen;' + arr[i].point_price + '集分</span></p><p class="p_bot"><span class="sucesORfail">' + arr[i].shuxing_zhi.replace(/'/g,'') + '</span><span class="red count">x' + arr[i].purchase_num + '</span></p></div></div>');
                listBox.append(list_con);
            }else if(arr[i].cash_price != '0.00' && arr[i].point_price != '0'){    //集分加现金商品
                var list_con = $('<div class="orderList_con"><div class="orderList_con_lt"><div class="lt_imgBox"><img class="IMG lazy'+ j +'" src="/Public/Product/img/loading2.gif" data-original="' + arr[i].show_pic + '" alt="" /></div></div><div class="orderList_con_rt"><p class="p_top"><span class="goodTitle">' + arr[i].pname + '</span><span class="red price">&yen;' + arr[i].cash_price + '元+' + arr[i].point_price + '集分</span></p><p class="p_bot"><span class="sucesORfail">' + arr[i].shuxing_zhi.replace(/'/g,'') + '</span><span class="red count">x' + arr[i].purchase_num + '</span></p></div></div>');
                listBox.append(list_con);
            } else if(arr[i].cash_price != '0.00' && arr[i].point_price == '0'){   //纯现金商品
                var list_con = $('<div class="orderList_con"><div class="orderList_con_lt"><div class="lt_imgBox"><img class="IMG lazy'+ j +'" src="/Public/Product/img/loading2.gif" data-original="' + arr[i].show_pic + '" alt="" /></div></div><div class="orderList_con_rt"><p class="p_top"><span class="goodTitle">' + arr[i].pname + '</span><span class="red price">&yen;' + arr[i].cash_price + '元</span></p><p class="p_bot"><span class="sucesORfail">' + arr[i].shuxing_zhi.replace(/'/g,'') + '</span><span class="red count">x' + arr[i].purchase_num + '</span></p></div></div>');
                listBox.append(list_con);
            }
        }
        if (total1 != '0.00' && total2 == '0') {     //纯现金商品
            var list_bot = $('<div class="orderList_bot"><p class="num-money">共<span class="good_piece pur">' + num + '</span>件商品，合计：&yen;<span class="allPrice pur">' + total1 + '元</span>(含运费&yen;3.0)</p><button class="payment fr">付款</button><button class="cancelOrder fr">取消订单</button></div>');
            listBox.append(list_bot);
        }else if(total1 == '0.00' && total2 != '0'){     //纯集分商品
            var list_bot = $('<div class="orderList_bot"><p class="num-money">共<span class="good_piece pur">' + num + '</span>件商品，合计：&yen;<span class="allPrice pur">' + total2 + '集分</span>(含运费&yen;3.0)</p><button class="payment fr">付款</button><button class="cancelOrder fr">取消订单</button></div>');
            listBox.append(list_bot);
        } else if(total1 != '0.00' && total2 != '0'){    //集分加现金商品
            var list_bot = $('<div class="orderList_bot"><p class="num-money">共<span class="good_piece pur">' + num + '</span>件商品，合计：&yen;<span class="allPrice pur">' + total1 + '元+' + total2 +'集分</span>(含运费&yen;3.0)</p><button class="payment fr">付款</button><button class="cancelOrder fr">取消订单</button></div>');
            listBox.append(list_bot);
        } else {    //集分加现金商品
            var list_bot = $('<div class="orderList_bot"><p class="num-money">共<span class="good_piece pur">' + num + '</span>件商品，合计：&yen;<span class="allPrice pur">' + total2 +'集分</span>(含运费&yen;3.0)</p><button class="payment fr">付款</button><button class="cancelOrder fr">取消订单</button></div>');
            listBox.append(list_bot);
        }
        List.append(listBox);
    }
	
	//点击订单获取订单号
	$(".orderList_box").bind("click",function(){
		var orderNum = $(this).find(".orderNum").text();
		console.log(orderNum);
	});
	
	//取消订单和支付
    function cancelORpay() {
        //点击取消订单按钮的事件，首先阻止事件冒泡
        $('.orderList_bot').off('click', '.cancelOrder').on('click', '.cancelOrder', function(e) {
            $('.confirm_cancel').find('.text').text('确认取消这笔订单吗？');
            var evt = e || window.event; //兼容IE
            evt.stopPropagation();
            $('html,body').addClass('ovfHiden');
            var OdNum = $(this).parents(".orderList_box").children(".orderList_num").children(".orderNum").text();
            console.log(OdNum);
            $('.mask').show();
            //阻止弹窗出来以后还可以滚动
            $('.mask,.confirm_cancel').bind("touchmove", function(e) {
                e.preventDefault();
            });
            $('.confirm_cancel').show().find('.sure').unbind('click').bind('click',function(){
                if (OdNum.substring(0,1) == 'Z') {
                    $.ajax({
                        url:"http://a.91jfk.com/Product/Order/order_cancel",
                        type:"post",
                        data:{
                            orderid:OdNum
                        },
                        dataType:'json',
                        success:function(res){
                            console.log(res);
                            if (res.code == '1') {
                                $('.confirm_cancel').hide();
                                $('.mask').hide();
                                $('.errAlert').addClass('AlertShow').text(res.msg);
                                setTimeout(function(){
                                    $('.errAlert').removeClass('AlertShow');
                                    window.location.reload();
                                },1500);
                            }
                        },
                        error:function(err){
                            console.log(err);
                        }
                    });
                } else if(OdNum.substring(0,1) == 'J'){
                    $.ajax({
                        url:"http://a.91jfk.com/Product/Ordershop/CancleOrder",
                        type:"post",
                        data:{
                            orderid:OdNum
                        },
                        dataType:'json',
                        success:function(res){
                            console.log(res);
                            $('.confirm_cancel').hide();
                            $('.mask').hide();
                            $('.errAlert').addClass('AlertShow').text(res.message);
                            setTimeout(function(){
                                $('.errAlert').removeClass('AlertShow');
                                window.location.reload();
                            },1500);
                        },
                        error:function(err){
                            console.log(err);
                        }
                    });
                }
            });
        });
        //点击付款按钮的事件，首先阻止事件冒泡
        var info_total = $('.info_price');      // 确认信息框的总金额
        var point = $('#pointPay');             // 纯集分支付弹框
        $('.orderList_bot').off('click', '.payment').on('click', '.payment', function(e) {
            var evt = e || window.event; // 兼容IE
            var OdNum = $(this).parents(".orderList_box").children(".orderList_num").children(".orderNum").text(); // 获取订单号码
            console.log(OdNum);
            var total = $(this).parents(".orderList_box").find(".allPrice").text();    // 储存应该付款的金额
            console.log(total);
            //点击圆圈选择支付方式
            var payWay; // 用于记录支付方式
            if (OdNum.substring(0,1) == 'Z') {
                $('.mask').show();                      // 蒙版
                $('.payment_foot').show();              // 支付弹窗
                evt.stopPropagation();                  // 阻止事件冒泡
                $('html,body').addClass('ovfHiden');    // 阻止弹框弹出以后页面继续滚动
                info_total.text(total);
                $('.mode_row').unbind('click').bind('click', function() {
                    $(this).children('.row_Rt').find('.pur').addClass('addCir');
                    $(this).siblings().children('.row_Rt').find('.pur').removeClass('addCir');
                    var payWay = $(this).children('input[type=hidden]').val();
                    console.log(payWay);
                    // payWay = $(this).children('.row_con').find('.mode_name').text();
                    // 点击确认支付，发送支付请求
                    $('.confirm_cfm').unbind('click').bind('click', function() {
                        if (payWay == '1') {
                            console.log('微信支付');
                            $.ajax({
                                url: "http://a.91jfk.com/Product/WxJsAPI/jsApiCall",
                                type: "post",
                                data: {
                                    orderId: OdNum
                                },
                                datatype: "json",
                                success: function(xhr) {
                                    console.log(xhr);
                                    var data = JSON.parse(xhr);
                                    callpay(data.jsApiParameters);
                                },
                                error: function(mes) {
                                    console.log('支付失败');
                                }
                            });//ajax结束
                        } else if(payWay == '2'){
                            console.log('2')
                        }
                    });
                });
            } else if(OdNum.substring(0,1) == 'J'){ 
                var goodType = $(this).parents(".orderList_box").children('.orderList_num').children('input[type=hidden]').val();  //1、纯集分 2、集分加现金 3、纯现金
                console.log(goodType);
                if (goodType == 1 || goodType == 2) {   //纯集分或集分加现金商品，先判断积分是否充足
                    $.ajax({
                        type:"post",
                        url:"http://a.91jfk.com/Product/Pointorder/JudgePoint",
                        data:{
                            orderid:OdNum
                        },
                        dataType:'json',
                        success:function(res){
                            console.log(res);
                            if (res.code == 1) {                  
                                if (goodType == 2) {                            // 集分加现金，前端只显示扣除的现金
                                    var strs = new Array();                     // 定义数组 
                                    strs = total.split("+");                    // 字符分割
                                    var point = strs[1].replace(/[^0-9]/ig,"");
                                    console.log(point); 
                                    if ((point - 0) <= (res.num - 0)) {         // 集分充足，可以支付
                                        $('.mask').show();                      // 蒙版
                                        $('.payment_foot').show();              // 支付弹窗
                                        evt.stopPropagation();                  // 阻止事件冒泡
                                        $('html,body').addClass('ovfHiden');    // 阻止弹框弹出以后页面继续滚动
                                        info_total.text(total);
                                        $('.mode_row').unbind('click').bind('click', function() {
                                            $(this).children('.row_Rt').find('.pur').addClass('addCir');
                                            $(this).siblings().children('.row_Rt').find('.pur').removeClass('addCir');
                                            var payWay = $(this).children('input[type=hidden]').val();
                                            console.log(payWay);
                                            // payWay = $(this).children('.row_con').find('.mode_name').text();
                                            // 点击确认支付，发送支付请求
                                            $('.confirm_cfm').unbind('click').bind('click', function() {
                                                if (payWay == '1') {
                                                    console.log('微信支付');
                                                    $.ajax({
                                                        url: "http://a.91jfk.com/Product/WxJsAPI/jsApiCall",
                                                        type: "post",
                                                        data: {
                                                            orderId: OdNum
                                                        },
                                                        datatype: "json",
                                                        success: function(xhr) {
                                                            console.log(xhr);
                                                            var data = JSON.parse(xhr);
                                                            callpay(data.jsApiParameters);
                                                        },
                                                        error: function(mes) {
                                                            console.log('支付失败');
                                                        }
                                                    });//ajax结束
                                                } else if(payWay == '2'){
                                                    console.log('2')
                                                }
                                            });
                                        });
                                    } else {
                                        $(".errAlert").text(res.message).addClass("AlertShow");
                                        setTimeout(function(){
                                            $(".errAlert").removeClass("AlertShow");
                                        },1500);
                                    }   
                                }
                                if (goodType == 1) {     //纯集分商品  显示账户总积分和商品所需积分
                                    var point1 = total.replace(/[^0-9]/ig,"");
                                    console.log(parseInt(point1));
                                    console.log(parseInt(res.num - 0));
                                    if ((point1 - 0) <= (res.num - 0)) {
                                        $('.mask').css('display','block');
                                        $('#pointPay').show().children('#pointPay_top').children('.formHoutai').text(res.num).siblings('.formCount').text(point1).parents('#pointPay').find('#point_sure').click("click",function(){	
                                            $.ajax({
                                                url:"http://a.91jfk.com/Product/Nowbuy/des_num",
                                                type:"post",
                                                data:{
                                                    orderid:OdNum
                                                },
                                                dataType:'json',
                                                success:function(res){
                                                    console.log(res);
                                                    $(".errAlert").text(res.message).addClass("AlertShow");
                                                    setTimeout(function(){
                                                        window.location.reload();
                                                        $(".errAlert").removeClass("AlertShow");
                                                    },1500);
                                                    $('.mask').hide();
                                                    $('#pointPay').hide();
                                                },
                                                error:function(err){
                                                    console.log(err);
                                                }
                                            });
                                        });
                                    } else {
                                        $(".errAlert").text(res.message).addClass("AlertShow");
                                        setTimeout(function(){
                                            $(".errAlert").removeClass("AlertShow");
                                        },1500);
                                    }
                                }
                            }else{
                                $(".errAlert").text(res.message).addClass("AlertShow");
                                setTimeout(function(){
                                    $(".errAlert").removeClass("AlertShow");
                                },1500);
                            }
                        },
                        error:function(err){
                            console.log(err);
                        }
                    });
                } else if(goodType == 3){                   // 纯现金商品
                    $('.mask').show();                      // 蒙版
                    $('.payment_foot').show();              // 支付弹窗
                    evt.stopPropagation();                  // 阻止事件冒泡
                    $('html,body').addClass('ovfHiden');    // 阻止弹框弹出以后页面继续滚动
                    info_total.text(total);                 // 支付信息弹框显示总金额
                    $('.mode_row').unbind('click').bind('click', function() {
                        $(this).children('.row_Rt').find('.pur').addClass('addCir');
                        $(this).siblings().children('.row_Rt').find('.pur').removeClass('addCir');
                        var payWay = $(this).children('input[type=hidden]').val();
                        console.log(payWay);
                        // payWay = $(this).children('.row_con').find('.mode_name').text();
                        // 点击确认支付，发送支付请求
                        $('.confirm_cfm').unbind('click').bind('click', function() {
                            if (payWay == '1') {
                                console.log('微信支付');
                                $.ajax({
                                    url: "http://a.91jfk.com/Product/WxJsAPI/jsApiCall",
                                    type: "post",
                                    data: {
                                        orderId: OdNum
                                    },
                                    datatype: "json",
                                    success: function(xhr) {
                                        console.log(xhr);
                                        var data = JSON.parse(xhr);
                                        callpay(data.jsApiParameters);
                                    },
                                    error: function(err) {
                                        console.log('支付失败');
                                    }
                                });// ajax结束
                            } else if(payWay == '2'){
                                console.log('连连支付');
                                //window.location.href = '';
                            } else{
                                $(".errAlert").text("请选择付款方式...").addClass("AlertShow");
                                setTimeout(function(){
                                    $(".errAlert").removeClass("AlertShow");
                                },1500);
                            }
                        });
                    });
                }
            }
        });
    }
	// 点击取消按钮
    $('.cancel').bind('click', function() {
        $('html,body').removeClass('ovfHiden');
        $('.mask').hide();
        $('.confirm_cancel').hide();
    });

    // 关闭付款弹框
    $('.closePay').bind('click', function(event) {
        event.stopPropagation();
        window.location.reload();
        $('html,body').removeClass('ovfHiden');
        $('.mask').hide();
        $('.payment_foot').hide();
    });

    //纯集分支付、取消支付
    $('#point_cancel').click(function(){
    	$('.mask').hide();
        $('#pointPay').hide();
        window.location.reload();
    });
    
    // 微信支付
    function callpay(arg) {
		if(typeof WeixinJSBridge == "undefined") {
			if(document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
			} else if(document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', jsApiCall);
				document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
			}
		} else {
			jsApiCall(arg);
		}
	}

	// 调用微信JS api 支付
	function jsApiCall(arg) {
		var data = JSON.parse(arg);
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			data,
			function(res) {
				WeixinJSBridge.log(res.err_msg);
				if(res.err_msg == "get_brand_wcpay_request:ok") {
					//alert("支付成功");
                    window.location.reload();
				} else if(res.err_msg == "get_brand_wcpay_request:cancel") {
                    //alert("取消支付");
                    window.location.reload();
				} else {
					//alert(res.err_msg);
					//alert("支付失败");
				}
			});
	}
});